from meowbit import *
import meowbit
def inputt():
    with open("keyborad.py","r") as file:
        keyborad=eval(file.read())
    
    screen.fill((0, 0, 0))
    screen.textSize(1)
    screen.setColor((255,255,255))
    
    txt=""
    dx=0
    zy=0
    zytxt=""
    zxs=0
    znls=[]
    
    jps=[
        ["q","w","e","r","t","y","u","i","o","p", ""],
        ["a","s","d","f","g","h","j","k","l", "", ""],
        ["z","x","c","v","b","n","m","", "", " ", ""]
    ]
    
    def inrufs(txts,zyt):
        screen.setColor((0,0,0))
        screen.drawRect(0,0,160,60,1)
        screen.setColor((255,255,255))
        screen.drawRect(1,19,158,1,0)
        screen.showText(txts,2,2)
        screen.showText(zyt,2,42)
    def showzy(py,kb):
        nonlocal znls,zxs
        screen.setColor((0,0,0))
        screen.drawRect(0,60,160,12,1)
        screen.setColor((255,255,255))
        n=0
        if py in kb:
            for x in kb[py]:
                screen.showText(x,n*12+2-(zxs*12),60)
                n+=1
            znls=kb[py]
        else:
            znls=[]
            
    def jp():
        screen.showText("qwertyuiop",2,70)
        screen.showText("asdfghjkl  ok",2,80)
        screen.showText("zxcvbnm",2,90)
        screen.drawRect(0,73,160,1,0)
        screen.drawRect(0,73,1,30,0)
        screen.drawRect(0,103,160,1,0)
        screen.drawRect(84,93,1,10,0)
        screen.drawRect(85,93,36,1,0)
        screen.drawRect(105,83,1,11,0)
        screen.drawRect(105,83,15,1,0)
        screen.drawRect(120,73,1,11,0)
        screen.showText("%",86,90)
        screen.drawRect(95,93,1,10,0)
        screen.showText("a",98,90)
        screen.drawRect(105,93,1,10,0)
        screen.showText("E",110,80)
        screen.drawRect(120,83,1,20,0)
        screen.drawRect(159,73,1,30,0)
    def rdx(dx):
        nonlocal jps
        if dx:
            screen.setColor((0,0,0))
            screen.showText("A",98,90)
            screen.setColor((255,255,255))
            screen.showText("a",98,90)
            dx=0
            jps=[
                ["q","w","e","r","t","y","u","i","o","p", ""],
                ["a","s","d","f","g","h","j","k","l", "", ""],
                ["z","x","c","v","b","n","m","", "", " ", ""]
            ]
        else:
            screen.setColor((0,0,0))
            screen.showText("a",98,90)
            screen.setColor((255,255,255))
            screen.showText("A",98,90)
            dx=1
            jps=[
                ["Q","W","E","R","T","Y","U","I","O","P", ""],
                ["A","S","D","F","G","H","J","K","L", "", ""],
                ["Z","X","C","V","B","N","M","", "", " ", ""]
            ]
        return dx
    def rzy(zy):
        if zy:
            screen.setColor((0,0,0))
            screen.showText("C",110,80)
            screen.setColor((255,255,255))
            screen.showText("E",110,80)
            zy=0
        else:
            screen.setColor((0,0,0))
            screen.showText("E",110,80)
            screen.setColor((255,255,255))
            screen.showText("C",110,80)
            zy=1
        return zy
    def getxymove(xs,ys):
        if y>=0:
            if xs<=9:
                screen.setColor((100,100,255))
                screen.drawRect(3+xs*12,82+ys*10,6,1,0)
                screen.setColor((255,255,255))
                screen.showText("ok",10*13+4,80)
            else:
                #10*12+2
                screen.setColor((255,216,0))
                screen.showText("ok",10*13+4,80)
                screen.setColor((255,255,255))
        else:
            screen.setColor((100,100,255))
            screen.drawRect(3+0*12,82+-1*10,6,1,0)
            screen.setColor((255,255,255))
            screen.showText("ok",10*13+4,80)
    inrufs(txt,zytxt)
    jp()
    x=0
    y=0
    getxymove(x,y)
    while True:
        if sensor.btnValue("down"):
            screen.setColor((0,0,0))
            screen.drawRect(3+x*12,82+y*10,6,1,0)
            if y==-1:
                screen.setColor((0,0,0))
                screen.drawRect(3+0*12,82+(-1*10),6,1,0)
                zxs=0
                
                showzy(zytxt,keyborad)
                x=0
            y+=1
            if y==3:
                y=0
            getxymove(x,y)
            while 1:
                if sensor.btnValue("down")==0:
                    break
        if sensor.btnValue("up"):
            screen.setColor((0,0,0))
            screen.drawRect(3+x*12,82+y*10,6,1,0)
            y-=1
            if zy==1:
                if y==-2:
                    screen.setColor((0,0,0))
                    screen.drawRect(3+0*12,82+(-1*10),6,1,0)
                    y=2
                    zxs=0
                    
                    showzy(zytxt,keyborad)
                if y==-1:
                    x=0
            else:
                if y==-1:
                    y=2
            getxymove(x,y)
            while 1:
                if sensor.btnValue("up")==0:
                    break
        if sensor.btnValue("right"):
            screen.setColor((0,0,0))
            screen.drawRect(3+x*12,82+y*10,6,1,0)
            x+=1
            if y>=0:
                if x==11:
                    x=0
            else:
                if x>=len(znls)-1:
                    x=len(znls)-1
                zxs=x
                showzy(zytxt,keyborad)
            getxymove(x,y)
            while 1:
                if sensor.btnValue("right")==0:
                    break
        if sensor.btnValue("left"):
            screen.setColor((0,0,0))
            screen.drawRect(3+x*12,82+y*10,6,1,0)
            x-=1
            if y>=0:
                if x==-1:
                    x=10
            else:
                if x<=-1:
                    x=0
                zxs=x
                showzy(zytxt,keyborad)
            getxymove(x,y)
            while 1:
                if sensor.btnValue("left")==0:
                    break
        if sensor.btnValue("a"):
            if x==8 and y==2:
                dx=rdx(dx)
            if x==9 and y==1:
                zy=rzy(zy)
                zytxt=""
            if zy==0:
                txt = txt + jps[y][x]
            else:
                if y==-1:
                    pass
                else:
                    zytxt=zytxt+jps[y][x]
            if y<0:
                if zytxt in keyborad:
                    if len(keyborad[zytxt])>0:
                        txt=txt+keyborad[zytxt][zxs]
                zxs=0
                x=0
                
                zytxt=""
            inrufs(txt,zytxt)
            showzy(zytxt,keyborad)
            if x==10 and y>=0:
                break
            while 1:
                if sensor.btnValue("a")==0:
                    break
        if sensor.btnValue("b"):
            if y==-1:
                x=0
                zxs=0
                showzy(zytxt,keyborad)
            if zytxt != "":
                zytxt=zytxt[:-1]
                inrufs(txt,zytxt)
                showzy(zytxt,keyborad)
            elif txt != "":
                txt=txt[:-1]
                inrufs(txt,zytxt)
                showzy(zytxt,keyborad)
            while 1:
                if sensor.btnValue("b")==0:
                    break
    del keyborad
    del dx
    del zy
    del zytxt
    del zxs
    del znls
    del jps
    del x
    del y
    
    del inrufs
    del showzy
    del jp
    del rdx
    del rzy
    del getxymove
    
    return txt
